package collection.exercise;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-02-02
 * Time:1:35
 */
@SuppressWarnings("all")
public class Exercise1 {
    public static void main(String[] args) {
        List<Dog> dogs = new ArrayList<>();
        dogs.add(new Dog("huahua", 3));
        dogs.add(new Dog("xiaohei", 2));
        dogs.add(new Dog("wangcai", 5));
        Iterator<Dog> iterator = dogs.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        for (Dog dog : dogs) {
            System.out.println(dog);
        }
    }
}

class Dog {
    String name;
    int age;

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }
}